 <?php 
function paging($totalRows,$curPg,$pg,$re,$file)    
{         
	$paging="";               
	$mxR = $re; 
	$mxP = $pg; 
	if($totalRows%$mxR==0)   
 		$totalPages = (int)($totalRows/$mxR); 
	else  
 		$totalPages = (int)($totalRows/$mxR+1); 
	$curRow = ($curPg-1)*$mxR+1; 
	if($totalRows>$mxR) 
	{ 
		$start=1; 
		$end=1; 
		$paging1 ="";           
		for($i=1;$i<=$totalPages;$i++) 
		{  
			if(($i>((int)(($curPg-1)/$mxP))* $mxP) && ($i<=((int)(($curPg-1)/$mxP+1))* $mxP)) 
 			{ 
  				if($start==1) $start=$i; 
  				if($i==$curPg)       
   					$paging1 .=  $i."&nbsp;&nbsp;"; 
  				else     
   				{ 
   					$paging1 .= "<a class=lslink  href='$file"; 
   					$paging1 .="&page=".$i."'>".$i; 
   					$paging1 .="</a>&nbsp;&nbsp;";  
   				} 
  				$end=$i;  
 			} 
		} 
		$paging.= "Trang :&nbsp;&nbsp;" ; 
		if($curPg>$mxP) 
 		{ 
 			$paging .="<a class=lslink href='$file"; 
 			$paging .="&page=".($start-1); 
 			$paging .="'>Previous</a>&nbsp;&nbsp;"; 
 		} 
		$paging.=$paging1; 
		if(((($curPg-1)/$mxP+1)*$mxP) < $totalPages) 
 		{ 
 			$paging .= "<a class=lslink href='$file"; 
 			$paging .="&page=".($end+1); 
 			$paging .="'>Next</a>&nbsp;&nbsp;"; 
 		} 
	} 
	return $paging; 
} 
?> 